import { Module } from 'vuex'
import { IUserState } from './types'
import initData from '../fnInitData'

const user: Module<IUserState, any> = {
  namespaced: true,
  state() {
    return {
      userInfo: initData('user', 'userInfo') || {},
      token: initData('user', 'token') || '',
      clientInfo: initData('user', 'clientInfo') || null
    }
  },
  mutations: {
    initInfo(state: any, newVal: any) {
      state.userInfo = newVal
    },
    initServerToken(state: any, newVal: any) {
      state.token = newVal
    },
    setClientInfo(state: any, newVal: any) {
      state.clientInfo = newVal
    }
  }
}

export default user
